/**
 * Description: 字符设备驱动客户端
 * File: clinet.c |Time: 2021-07-04 12:37
 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

#define ERR(msg) do{    \
    perror(msg);   \
    printf("%s:%s %d\n", __FILE__, __func__, __LINE__); \
    exit(EXIT_FAILURE);    \
} while(0)

#define BUFSIZE 128

int main(int argc, const char *argv[])
{
    int fd = open("/dev/demodev", O_RDWR);
    int ret;
    char buf[BUFSIZE];
    if (fd < 0) 
    {
        ERR("open");
    }

    ret = read(fd, buf, sizeof(buf));
    if (ret < 0) 
    {
        ERR("read");
    }

    ret = write(fd, buf, sizeof(buf));
    if (ret < 0) 
    {
        ERR("write");
    }


    ret = close(fd);
    if (ret < 0) 
    {
        ERR("close");
    }
    
    return 0;
}



